package com.example.springboot.event;

import com.example.springboot.service.TeacherService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 企业申领印章事件
 */
@Service
public class CompanyApplySealEventListener {

    /**
     * 日志管理组件
     */
    private static final Logger log = LoggerFactory.getLogger(CompanyApplySealEventListener.class);

    @Autowired
    private TeacherService teacherService;

    /**
     * 异步执行，async注解
     * 登录事件监听器
     */
    @EventListener(CompanyApplySealEvent.class)
    @Transactional(rollbackFor = Exception.class)
    public void consumer(CompanyApplySealEvent event) {
        String sealMakeStatus = event.getConsumer().getSealMakeStatus();
        log.info("监听到企业申领印章事件event:{}", sealMakeStatus);
        log.info("线程：" + Thread.currentThread().getName() + sealMakeStatus);
        teacherService.save(sealMakeStatus);
        if (sealMakeStatus.equals("3")) {
            System.out.println(1/0);
        }
        log.info("企业申领印章事件监听完成：" + sealMakeStatus);
    }




}
